<?php
/**
 * (exporter)
 */
namespace App\Exporter\Delivery;

use App\Models\Basics\SysPlatAccount;
use App\Models\Delivery\OSDelivery;
use App\Models\Product\ProductClassify;
use App\Util\User;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\WithMapping;
class OSDetailExporter extends ExcelExporter implements WithMapping
{

    protected $fileName = '海外仓发货单明细.csv';

    protected $headings = ['发货单','销售员','目的仓库','发货站点','SKU',
        '产品名称','季节性','品类','状态','物流状态','账号','FNSKU','数量','已确定数量','发货时间','追踪号','备注'];

    public function map($model) : array
    {
        return [
            $model->delivery_no,
            User::getUsernameById($model->delivery->seller_id ?? -1),
            $model->delivery->warehouse->w_code ?? '',
            $model->delivery->area->area ?? '',
            $model->sku->psku_code ?? '',
            $model->sku->psku_cn ?? '',
            ProductClassify::$_season[$model->skuClassify->season ?? 3],
            $model->skuClassify->title ?? '',
            array_key_exists($model->delivery->status ?? 1,OSDelivery::$_status) ? OSDelivery::$_status[$model->delivery->status ?? 1] : '',
            array_key_exists($model->delivery->logistics_status ?? 1,OSDelivery::$_logisticsStatus) ? OSDelivery::$_logisticsStatus[$model->delivery->logistics_status ?? 1] : '',
            SysPlatAccount::getAccountById($model->account_id),
            $model->fnsku,
            $model->apply_num,
            $model->ship_num,
            $model->delivery->delivered_at ?? '',
            $model->delivery->logistics->tracking_no ?? '',
            $model->delivery->remarks ?? '',
        ];
    }
}
